'use strict';

const BaseInit = require('../../libs/base/BaseInit');
const Hall = require('./Hall');
const PlayerManager = require('./player/PlayerManager');

/**
 * Game进程初始化
 */
class Init extends BaseInit {
  /**
   * 构造函数
   */
  constructor() {
    // 从命令行参数获取服务名称
    const serviceName = process.argv[2] || 'Hall';
    super(serviceName);
  }

  /**
   * 创建服务实例
   */
  async createService() {
    await this.createOneService('Hall', Hall);
    await this.createOneService('PlayerManager', PlayerManager);
  }
}

// 创建并初始化Main服务
const service = new Init();

// 启动初始化流程
service.init().catch(error => {
  console.error('[game] 初始化失败:', error);
  process.exit(1);
});

// 监听未捕获的异常
process.on('uncaughtException', (err) => {
  console.error('[Game] 未捕获的异常:', err);
});

// 监听未处理的Promise拒绝
process.on('unhandledRejection', (reason, promise) => {
  console.error('[Game] 未处理的Promise拒绝:', reason);
});
